#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

bool decode(const string &log, int &uni, int &time)
{
    int i = log.find(':'), j = log.find(':', i + 1);
    uni = stoi(log.substr(0, i)), time = stoi(log.substr(j + 1, log.size() - j - 1));
    return log[i + 1] == 's' ? true : false;
}

vector<int> exclusiveTime(int n, vector<string> &logs)
{
    int uni = 0, time = 0;
    vector<int> uni_stk, time_stk, ctime(n, 0);
    for (size_t i = 0; i < logs.size(); i++)
    {
        if (decode(logs[i], uni, time))
        {
            if (!uni_stk.empty())
                ctime[uni_stk.back()] += time - time_stk.back();
            uni_stk.push_back(uni);
            time_stk.push_back(time);
        }
        else
        {
            ctime[uni] += time - time_stk.back() + 1;
            uni_stk.pop_back();
            time_stk.pop_back();
            if (!time_stk.empty())
                *(time_stk.end() - 1) = time + 1;
        }
    }
    return ctime;
}

int main()
{
    int n = 2;
    vector<string> logs = {"0:start:0", "0:start:2", "0:end:5", "1:start:7", "1:end:7", "0:end:8"};
    vector<int> r = exclusiveTime(n, logs);
    for (int i : r)
    {
        cout << i << endl;
    }
    return 0;
}
